'use strict';

const {
	Controller
} = require('uni-cloud-router');
const dbcmd = uniCloud.database().command;

module.exports = class AppController extends Controller {
	// 设置分类导航数量
	async parameter() {
		let response = {
			code: 1,
			datas: ''
		};

		let start = new Date().getTime();
		// 请求参数
		const req = this.ctx.data;

		const parameterRes = await this.db.collection('usemall-app-parameter').doc('usemall-app-parameter').get();
		if (parameterRes.data && parameterRes.data.length == 1) {
			await this.db.collection('usemall-app-parameter').doc('usemall-app-parameter').update(req);
		} else {
			await this.db.collection('usemall-app-parameter').add({ _id: 'usemall-app-parameter', ...req });
		}
		
		response.datas = '操作成功';

		let end = new Date().getTime();
		console.log(`耗时：${end - start}ms`);
		response.code = 0;
		response.msg = `耗时：${end - start}ms`;
		return response;
	}
}
